package com.wxp.demo04.global;

import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.widget.EditText;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

import com.wxp.demo04.R;

/**
 * 3.2 读取元数据配置信息
 */
public class MetaDataActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_meta_data);

        this.setTitle("3.2 读取元数据配置信息");
        EditText editText = this.findViewById(R.id.show_text);

        //获取应用包管理器
        PackageManager packageManager = this.getPackageManager();
        try {
            //从包应用管理器中获取当前活动信息
            ActivityInfo activityInfo = packageManager.getActivityInfo(this.getComponentName(), PackageManager.GET_META_DATA);
            //获取活动附加的元数据信息
            Bundle metaData = activityInfo.metaData;
            String mateDev = metaData.getString("mate_dev");
            String mateQuote = metaData.getString("mate_quote");

            editText.setText("mate_dev：" + mateDev + "\n" + "mate_quote：" + mateQuote);

        } catch (PackageManager.NameNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}